<template>
  <div class="container">
    <el-dialog title="题目预览" :visible="showDialog" @close="closeDialog">
      <el-row>
        <el-col :span="6">
          <div class="logDiv">
            【题型】：{{ formatterType(questionsData.questionType) }}
          </div>
          <div class="logDiv">【学科】：{{ questionsData.subjectName }}</div>
        </el-col>
        <el-col :span="6">
          <div class="logDiv">【编号】：{{ questionsData.id }}</div>
          <div class="logDiv">【目录】：{{ questionsData.directoryName }}</div>
        </el-col>
        <el-col :span="6">
          <div class="logDiv">
            【难度】：{{ formatterDifficulty(questionsData.difficulty) }}
          </div>
          <div class="logDiv">【方向】：{{ questionsData.direction }}</div>
        </el-col>
        <el-col :span="6">
          <div class="logDiv">【标签】：{{ questionsData.tags }}</div>
        </el-col>
      </el-row>
      <hr />
      <div class="logDiv">
        【题干】：
        <p class="blue">{{ questionsData.question | html2Text }}</p>
        <p>
          {{
            formatterType(questionsData.questionType)
          }}&nbsp;&nbsp;&nbsp;&nbsp;选项：（以下选中的选项为正确答案）
        </p>
        <!-- 单选 -->
        <div v-if="questionsData.questionType === '1'">
          <el-radio-group :value="1">
            <el-radio
              v-for="item in questionsData.options"
              :key="item.id"
              :label="item.isRight"
            >
              {{ item.title }}
            </el-radio>
          </el-radio-group>
        </div>
        <!-- 多选 -->
        <div v-if="questionsData.questionType === '2'">
          <el-checkbox-group :value="[1]">
            <el-checkbox
              v-for="item in questionsData.options"
              :key="item.id"
              :label="item.isRight"
            >
              {{ item.title }}
            </el-checkbox>
          </el-checkbox-group>
        </div>
        <!-- 简答 -->
        <div v-if="questionsData.questionType === '3'">
          {{ questionsData.question | html2Text }}
        </div>
      </div>
      <hr />
      <div class="logDiv">
        【参考答案】：<el-button type="danger" @click="showVideo = true"
          >视频答案预览</el-button
        >
        <div v-if="showVideo">
          <video
            :src="questionsData.videoURL"
            controls
            autoplay
            muted
            loop
            style="width: 400px; height: 300px"
          ></video>
        </div>
      </div>
      <hr />
      <div class="logDiv">
        【答案解析】：{{ questionsData.answer | html2Text }}
      </div>
      <hr />
      <div class="logDiv">【题目备注】：{{ questionsData.remarks }}</div>
      <div slot="footer">
        <el-row type="flex" justify="end">
          <el-button @click="closeDialog" type="primary">关闭</el-button>
        </el-row>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { questionType, difficulty } from '@/api/hmmm/constants.js'
export default {
  name: 'questions-preview',
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    questionsData: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      showVideo: false
    }
  },
  methods: {
    closeDialog () {
      this.$emit('update:showDialog', false)
    },
    formatterType (val) {
      const obj = questionType.find(item => item.value === val - 0)
      return obj ? obj.label : '未知'
    },
    formatterDifficulty (val) {
      const obj = difficulty.find(item => item.value === val - 0)
      return obj ? obj.label : '未知'
    }
  }
}
</script>

<style>
.logDiv {
  padding: 10px 0;
}
.el-dialog {
  width: 900px;
}
.el-radio,
.el-checkbox {
  display: block;
  padding: 8px 0;
}
.blue {
  color: blue;
}
</style>
